define(['jquery','jquery_ext','config','common','md5','validform'], function($,jqext,config,common,md5) {
	var Account = {
			//用户信息
			userInfo:{}
	};
	/**
	 * 修改密码
	 */
	Account.changepwd = function(){
		var hangepwdfrm=$("#hangepwdmodal form").Validform({
			tiptype:3,
			isShowRight:false
		});
		if(hangepwdfrm.check()){
			var $frm = $('#hangepwdmodal form').serializeArray();
			$.each($frm,function(_index,_data){
				_data['value']=md5(_data['value']);
			});
			common.ajax_request2('post','/api/v1/changepwd',$frm,function($code,$data,$business){
				if($code == '200'){
					$('#hangepwdmodal form')[0].reset();
					$('#hangepwdmodal .errinfo').removeClass('Validform_wrong').addClass('Validform_right').html('密码修改成功!请妥善保管你的密码!');
					Account.loginOut();
				}else{
					if($business){
						$('#hangepwdmodal .errinfo').removeClass('Validform_right').addClass('Validform_wrong').html($business.businessNote);
					}else{
						$('#hangepwdmodal .errinfo').removeClass('Validform_right').addClass('Validform_wrong').html('密码修改失败!');
					}
				}
			});
		}
	};
	
	/**
	 * 退出登录
	 */
	Account.loginOut = function(){
		//检测用户是否登录没有登录跳转到登录
		//$.cookie("token",null);
		//document.cookie = 'token=';
		common.ajax_request2('get','/auth/logout',{},function($code,$data){
			//跳转登录
			common.toLogin();
		});
	};
	window.loginOut=Account.loginOut;
	
	
	/**
	 * 检测登录
	 */
	Account.checkLogin = function(){
		//检测用户是否登录没有登录跳转到登录
		common.ajax_request2('post','/api/auth/asscessCheck');
	};
	
	/**
	 * 初始化用户信息
	 */
	Account.initUserInfo = function(){
		common.ajax_request2('get','/topic/getSessionUser',{},function($data){
			Account.userInfo=$data;
			/*if(typeof $data.nick_name === 'string' && $data.nick_name != ''){
				$('.dropdown-toggle span:first').html($data.nick_name);
			}else{
				$('.dropdown-toggle span:first').html($data.userName);
			}*/
		},false);
	};
	Account.initUserInfo();
	
	
	// 初始化用户弹窗信息
	/*Account.init = function(){
		$('.dropdown-menu').on('click','a:first',function(e){
			e.preventDefault();
			$('#hangepwdmodal form')[0].reset();
			$('#hangepwdmodal .errinfo').removeClass('Validform_right').removeClass('Validform_wrong').html('');
			$('#hangepwdmodal').modal('show');
		});
		
		$('#hangepwdmodal').on('click','.btn-primary',function(e){
			e.preventDefault();
			Account.changepwd();
		});
		// 退出
		$('.navbar-right .dropdown-menu').on('click','a:last',function(e){
			e.preventDefault();
			Account.loginOut();
		});
	};*/
	//Account.init();
	return {
		checkLogin:Account.checkLogin,
		userInfo:Account.userInfo,
		changepwd:Account.changepwd,
		loginOut:Account.loginOut
	};
});
